﻿<%@ WebHandler Language="C#" Class="detail" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using System.Collections;

public class detail : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

       
        string onlyId = context.Request.Headers["X-ACCESS-USER"];//Header中的token
        var xxx=HttpContext.Current.Request.Form["paramJson"];
        JObject jo = (JObject)JsonConvert.DeserializeObject(xxx);
        //{"onlyId":"osiiR5U1hlyCzRDjGqFWWGzE5eqo","taskid":4,"content_text":"eq ","content_images":"","content_video":""}


        string taskid = jo["taskid"].ToString();
        string content_images = jo["content_images"].ToString();

        string content_video = jo["content_video"].ToString();
        string content_text = jo["content_text"].ToString();
        if (string.IsNullOrEmpty(taskid))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }

        var code = 1;
        var msg = "添加成功";
        var time = DateTime.Now;

        using (Entities bll = new Entities())
        {
            int tid = int.Parse(taskid);

            P_T_Detail mytask = new P_T_Detail();

            //新建一个JArray对象，可以理解成json对象中 value 位置的数组对象 ->  []

            mytask.TaskID = tid;
            mytask.addtime = DateTime.Now;
            mytask.UserId = onlyId;
            mytask.content_video = content_video;
            mytask.content_images = content_images;
            mytask.content_text = content_text;
                bll.P_T_Detail.Add(mytask);
                bll.SaveChanges();


            context.Response.Write(JsonConvert.SerializeObject(new { code,msg,time,mytask.id}));

        }

        HttpContext.Current.Response.End();
        //context.Response.Write("Hello World");


    }





    public bool IsReusable {
        get {
            return false;
        }
    }

}